/*
    Bandleader
    Copyright (c) 2006 by Grant Yoshida

    Licensed under the GPL version 2 or later,
    please see COPYING for details.
*/

#include "InsertBar.h"
//
#include "ChordView.h"
#include "Document.h"

InsertBar::InsertBar(ChordView *view, int index, QUndoCommand *parent) :
    QUndoCommand("Insert Bar", parent),
    m_view(view),
    m_document(),
    m_index(index),
    m_newIndex(index)
{
    if (m_view)
        m_document = m_view->getDocument();
}

void InsertBar::undo()
{
    if (m_document)
        m_document->deleteBar(m_newIndex);

    if (m_view)
        m_view->setCursorPosition(m_index);

    QUndoCommand::undo();
}

void InsertBar::redo()
{
    if (m_document) {
        m_document->insertEmptyBar(m_index);

        m_newIndex = 
            m_document->indexOf(
                m_document->barNumberOf(m_index));
    }

    if (m_view) {
        m_view->setCursorPosition(m_newIndex);
    }

    QUndoCommand::redo();
}
